config := meta.(*Config)

// current import_formats cannot import fields with forward slashes in their value
if err := parseImportId([]string{"(?P<name>.+)"}, d, config); err != nil {
	return nil, err
}

nameParts := strings.Split(d.Get("name").(string), "/")
if len(nameParts) == 4 {
	// `organizations/{{org_name}}/instances/{{name}}`
	orgId := fmt.Sprintf("organizations/%s", nameParts[1])
	if err := d.Set("org_id", orgId); err != nil {
		return nil, fmt.Errorf("Error setting org_id: %s", err)
	}
	if err := d.Set("name", nameParts[3]); err != nil {
		return nil, fmt.Errorf("Error setting name: %s", err)
	}
} else if len(nameParts) == 3 {
	// `organizations/{{org_name}}/{{name}}`
	orgId := fmt.Sprintf("organizations/%s", nameParts[1])
	if err := d.Set("org_id", orgId); err != nil {
		return nil, fmt.Errorf("Error setting org_id: %s", err)
	}
	if err := d.Set("name", nameParts[2]); err != nil {
		return nil, fmt.Errorf("Error setting name: %s", err)
	}
} else {
	return nil, fmt.Errorf(
		"Saw %s when the name is expected to have shape %s or %s",
		d.Get("name"),
		"organizations/{{org_name}}/instances/{{name}}",
		"organizations/{{org_name}}/{{name}}")
}

// Replace import id for the resource id
id, err := replaceVars(d, config, "{{org_id}}/instances/{{name}}")
if err != nil {
	return nil, fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)

return []*schema.ResourceData{d}, nil
